import logging
from webapp2 import Route, WSGIApplication
from webapp2_extras.routes import HandlerPrefixRoute
from google.appengine.ext.webapp.util import run_wsgi_app



DEBUG = False


routes = [
    HandlerPrefixRoute('handlers.', [
        Route(r'/',                           'login.LoginPage',                       'main'),
        
        Route(r'/login',                      'login.LoginPage',                       'login'),
        
        Route(r'/register',                   'register.RegisterPage',                 'register'),
        Route(r'/register/success',           'register.SuccessPage',                  'register_success'),
        Route(r'/register/transaction-fail',  'register.TransactionFailPage',          'register_transaction_fail'),
        
        Route(r'/recovery',                   'password_recovery.RecoveryPage',        'password_recovery'),
        Route(r'/recovery/sent',              'password_recovery.PasswordSentPage',    'password_recovery_sent'),
        Route(r'/recovery/new',               'password_recovery.NewPasswordPage',     'password_recovery_new'),
        Route(r'/recovery/success',           'password_recovery.SuccessPage',         'password_recovery_success'),
        Route(r'/recovery/transaction-fail',  'password_recovery.TransactionFailPage', 'password_recovery_transaction_fail'),
        Route(r'/recovery/user-not-found',    'password_recovery.UserNotFoundPage',    'password_recovery_user_not_found'),
        Route(r'/recovery/request-not-found', 'password_recovery.RequestNotFoundPage', 'password_recovery_request_not_found'),
        
        Route(r'/chat',                       'chat.ChatPage',                         'chat'),
        Route(r'/chat/send-message',          'chat.MessagePage',                      'chat_message'),
        Route(r'/_ah/channel/connected/',     'chat.ChannelConnectPage'),
        Route(r'/_ah/channel/disconnected/',  'chat.ChannelDisconnectPage'),
        
        Route(r'/files/upload/form',          'files.SelectFileForm',                  'file_upload_form'),
        Route(r'/files/upload',               'files.FileUpload',                      'file_upload'),
        Route(r'/files/download/<blob_key>',  'files.FileDownload',                    'file_download'),
        
        Route(r'/history/<username>',         'history.HistoryPage',                   'history')
    ])
]


application = WSGIApplication(
    routes,
    config=None,
    debug=DEBUG
)


def main():
    if DEBUG:
        # Show debug log messages.
        logging.getLogger().setLevel(logging.DEBUG)
    run_wsgi_app(application)


if __name__ == "__main__":
    main()